import os
from configparser import ConfigParser


def read_ini(filename):
    con = ConfigParser()
    file_path = os.path.relpath(filename)
    con.read(file_path)
    DIALECT = con.get('flask-mysql', 'DIALECT')
    DRIVER = con.get('flask-mysql', 'DRIVER')
    USERNAME = con.get('flask-mysql', 'USERNAME')
    PASSWORD = con.get('flask-mysql', 'PASSWORD')
    HOST = con.get('flask-mysql', 'HOST')
    PORT = con.get('flask-mysql', 'PORT')
    DATABASE = con.get('flask-mysql', 'DATABASE')
    SQLALCHEMY_DATABASE_URI = '{}+{}://{}:{}@{}:{}/{}?charset=utf8'.format(
        DIALECT, DRIVER, USERNAME, PASSWORD, HOST, PORT, DATABASE
    )

    return SQLALCHEMY_DATABASE_URI
